import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import user from '../components/user/user.vue'
import Item from '../components/items/Item.vue'
import addItem from '../components/items/addItem.vue'
import ItemCat from '../components/items/ItemCat.vue'
import XueJi from '../components/Stu/XueJi.vue'
//使用路由机制
Vue.use(VueRouter)
const routes = [
  {path: '/', redirect: '/login'},
  {path: '/login', component: Login},
  {path: '/home',component: Home, children: [
    {path: '/user',component: user},
    {path: '/item',component: Item},
    {path: '/item/addItem',component: addItem},
    {path: '/itemCat',component: ItemCat},
    {path: '/rights',component: XueJi}
  ]}
]

//路由导航守卫!!!!!!!

/* router.beforeEach((to,from,next) => {
   if(to.path === '/login') {
     return next()
   }
   let token = window.sessionStorage.getItem('tokne')
   if(token === null || token ===''){
     return next('/login')
     alert("用户名或密码输入错误！")
   }
   next()
}) */

const router = new VueRouter({
  mode: 'history',
  routes
})

export default router
